home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / slipscripts1_3.lha / SLIPStart.rexx < prev    next >
OS/2 REXX Batch file  |  1995-02-03  |  7KB  |  163 lines

  1. /* SLIPStart.rexx  ver 1.3  Feb. 3, 1995   by Travis Pascoe               */
  2. /*                                         pasc8891@raven.csrv.uidaho.edu */
  3. /*                                                                        */
  4. /*   SLIPStart is an ARexx script used to connect to a host with          */
  5. /*   dynamic slip IP assignment and initialize the AmiTCP stack.          */
  6. /*   The script is based on a script by Bradley Tinder with several       */
  7. /*   blatant errors and bugs removed (sorry Bradley).  [Bradley was       */
  8. /*   inspired by Dave Bolen's REXX/2 SLIPUP.CMD for IBM OS/2.]            */
  9. /*   This script is intended mainly as a model and an example for         */
  10. /*   automating SLIP dialup.                                              */
  11. /*                                                                        */
  12. /*   Requirements:   ARexx   (obviously)                                  */
  13. /*                   rexxserdev.library ver 5.02+   (see Aminet)          */
  14. /*                                      by Joseph M. Stivaletta           */
  15. /*                   AmiTCP ver 3.0b+                                     */
  16. /*                                                                        */
  17. /*   Usage:          From a cli, type:    rx slipstart                    */
  18. /*                                                                        */
  19. /*   Warning:        You WILL need to modify the script in several        */
  20. /*                   places to suit your host dialup terminal.            */
  21. /*                   Follow the comments below for assistance.            */
  22. /*                   The example below works with my university's         */
  23. /*                   Xylogics terminal server.                            */
  24.  
  25.  
  26.     if ~show('L',"rexxsupport.library") then
  27.     if ~addlib('rexxsupport.library', 0, -30, 0) then exit 41
  28.     if ~show('L', "rexxserdev.library") then
  29.     if ~addlib( 'rexxserdev.library', 0, -30, 0) then exit 42
  30.  
  31.     signal on break_c
  32.     cr        = '0d'x
  33.     initstr1  = 'ATZ'||cr                /* modem init, change as desired */
  34.     initstr2  = 'AT&D0'||cr              /* set ignore carrier detect !!  */
  35.     dialstr   = 'atdt555-1234'||cr       /* number to dial                */
  36.     slip_cmd  = '30'||cr                 /* selection number for SLIP     */
  37.     username  = 'myname'||cr             /* change to your account name   */
  38.     passwd    = 'mypassword'||cr         /* change to your account passwd */
  39.  
  40.     dh        = SerOpen('serial.device', 0)
  41.     if (dh == 0) then do; say 'Cannot open serial.device'; exit 43; end
  42.     check     = SerClear(dh)
  43.     /* I use 38400 modem-computer speed, change as desired                */
  44.     check     = SerSetParms(dh, 38400, 8, N, 1, 0, 250000, 4096)
  45.     buffer    = AllocMem(4096)
  46.     junk      = c2d(buffer)
  47.     check     = 0
  48.     connected = 0      /* flag for modem connection -- suggested by       */
  49.                        /*                      _Bucky_ of IRC fame.       */
  50.                        /* (makes ctrl-c breaks a little cleaner...thanks) */
  51.  
  52.     say 'Dialing SLIP service... '
  53.     SerWrite(dh, initstr1, length(initstr1))
  54.     Delay(200)
  55.     SerWrite(dh, initstr2, length(initstr2))
  56.     do forever             /* loop until connect, use ctrl-c to break out */
  57.         delay(100)
  58.         if (check == 0) then
  59.         do
  60.             result = SerWrite(dh, dialstr, length(dialstr))
  61.             check = 1
  62.             totalstr = ''
  63.         end
  64.         status   = SerQuery(dh)
  65.         parse upper var status valid bytes_read .
  66.         rcvdstrg = SerRead(dh, junk, bytes_read)
  67.         totalstr = totalstr||rcvdstrg
  68.         check    = modem_query(totalstr)
  69.         if (check == 100) then leave
  70.         if (check == 101) then do; check = 0; say 'BUSY'; end
  71.         if (check == 102) then do; check = 0; say 'NO CARRIER'; end
  72.     end
  73.     connect = 1
  74.     parse var totalstr .'CONNECT ' speed+5 +2 totalstr
  75.     say 'Connected at '||speed||'.'
  76.  
  77.     call wait_str(']:')      /* these chars signal the first terminal */
  78.                              /* prompt, change as needed              */
  79.     SerWrite(dh, slip_cmd, length(slip_cmd))
  80.     say 'SLIP selection made.'
  81.  
  82.     call wait_str('Username: ')   /* wait for username prompt, change */
  83.                                   /* as needed                        */
  84.     SerWrite(dh, username, length(username))
  85.     say 'Username sent.'
  86.  
  87.     call wait_str('Password: ')   /* wait for password prompt, change */
  88.                                   /* as needed                        */
  89.     SerWrite(dh, passwd, length(passwd))
  90.     say 'Password sent.'
  91.     call wait_str('Annex')        /* annex string signals the line    */
  92.                                   /* that contains the dynamic IP     */
  93.  
  94.     SerClose(dh)
  95.     /* the parse command below extracts the IP address from rcvdstr,  */
  96.     /* change as needed   (should work with variable length IPs now)  */
  97.     parse var rcvdstr . 'Your address is ' a '.' b '.' c '.' d '.'.
  98.     slip_ip = a||'.'||b||'.'||c||'.'||d
  99.     say 'Current SLIP address is:  '||slip_ip
  100.     time_ip = time('c')||'   '||date()
  101.     say 'Connect time:  '||time_ip
  102.  
  103.     address command
  104.     'setenv ip '||slip_ip         /* ip is the current dynamic IP     */
  105.     'setenv iptime '||time_ip     /* iptime is the connect time       */
  106.     'copy ENV:ip ENVARC:oldip'    /* save ip as oldip for SLIPresume  */
  107.     'copy ENV:iptime ENVARC:oldiptime'
  108.     /* I use cslip and 38400 modem-computer speed, change as desired  */
  109.     'echo >ENV:sana2/rhcslip0.config "serial.device 0 38400 $ip"'
  110.     /* change hostname and alias as desired                           */
  111.     'echo >AmiTCP:db/netdb-myhost "HOST $ip me.mydomain.edu me"'
  112.     /* change domain as needed                                        */
  113.     'echo >>AmiTCP:db/netdb-myhost "DOMAIN 129.123.45.6"'
  114.     /* change nameserver as needed                                    */
  115.     'echo >>AmiTCP:db/netdb-myhost "NAMESERVER 129.123.123.4"'
  116.     'startnet'
  117.     /* if using rhslip above, use rhslip here also otherwise rhcslip  */
  118.     'online rhcslip.device 0'
  119.     
  120.     call FreeMem(buffer,4096)
  121. exit 0
  122.  
  123. /* Exit point for "Break C" or ^C         */
  124. /*----------------------------------------*/
  125. break_c:
  126.     say '***Break'
  127.     if connected ~= 0 then                  /* Thanks again _Bucky_ 8)  */
  128.     do
  129.       say 'Hanging up modem.'
  130.       check = SerWrite(dh, '+++', 3)
  131.       check = Delay(100)
  132.       check = SerWrite(dh, 'ATH0'||cr , 5)
  133.     end
  134.     SerClose(dh)
  135.     FreeMem(buffer,4096)
  136. exit 20
  137.  
  138. /* wait_str  returns when arg is received */
  139. /* ---------------------------------------*/
  140. wait_str:
  141.     teststr = arg(1)
  142.     check = 0
  143.     do until (check ~= 0)
  144.         status   = SerQuery(dh)
  145.         parse upper var status valid bytes_read .
  146.         rcvdstr  = SerRead(dh, junk, bytes_read)
  147.         totalstr = totalstr||rcvdstr
  148.         check    = pos(teststr,totalstr)
  149.         Delay(20)
  150.     end
  151.     rcvdstr  = totalstr
  152.     totalstr = ''
  153. return 0
  154.  
  155. /* modem_query   determine modem status   */
  156. /*----------------------------------------*/
  157. modem_query:
  158.     teststr = arg(1)
  159.     if (pos('CONNECT'   , teststr) ~= 0) then return 100
  160.     if (pos('BUSY'      , teststr) ~= 0) then return 101
  161.     if (pos('NO CARRIER', teststr) ~= 0) then return 102
  162. return 200
  163.